package com.itheima;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

public class Demo04 {

    public static void main(String[] args) {

        Student s1 = new Student("黄晓明---明学",45);
        Student s2 = new Student("卢本伟---科学家",27);
        Student s3 = new Student("孙笑川---天皇",43);
        Student s4 = new Student("章金莱---六学",66);
        Student s5 = new Student("刘波---艺术家",30);


        Collection<Student> c = new ArrayList<>();

        c.add(s1);
        c.add(s2);
        c.add(s3);
        c.add(s4);
        c.add(s5);

        Iterator<Student> iterator = c.iterator();

        while (iterator.hasNext()){
            Student next = iterator.next();
            System.out.println(next.getName()+"    "+next.getAge());
        }

        System.out.println("----------------------------------------");

        for(Student a : c){
            System.out.println(a.getName()+"     "+a.getAge());
        }

        System.out.println("------------------------------------------");

        /*c.forEach(new Consumer<Student>() {
            @Override
            public void accept(Student student) {
                System.out.println(student.getName()+"    "+student.getAge());
            }
        });*/


        c.forEach(student -> System.out.println(student.getName()+"    "+student.getAge()));
    }
}
